import React, {useState, useEffect, memo} from 'react'
import {connect} from 'umi'
import styles from './index.less'
import CustomTable from '@/components/Table'
import {getStocktakePage} from '@/service/carMessage/list'

const standbyAdd = memo((props: any) => {
	const {data} = props
	const [params, setParams] = useState({
		current: 1,
		size: 10,
	})
	const [total, setTotal] = useState(0)
	const [loading, setLoading] = useState(false)
	const [tableList, setTableList] = useState<any[]>([])

	useEffect(() => {
		getStocktakePage({...params, carId: data?.id})
			.then((res: any) => {
				if (res?.success) {
					setTableList(() => res.data.records)
					setTotal(res.data.total)
				}
				setLoading(false)
			})
			.catch(() => {
				setLoading(false)
			})
	}, [])

	const columns: any = [
		{
			title: '盘点日期',
			dataIndex: 'stocktakeTime',
			align: 'center',
			width: 200,
			render: (text: string) => <span>{text || '--'}</span>,
		},
		{
			title: '盘点人',
			dataIndex: 'stocktakeName',
			align: 'center',
			width: 140,
			render: (text: string) => <span>{text || '--'}</span>,
		},
		{
			title: '盘点类型',
			dataIndex: 'stocktakeType',
			align: 'center',
			width: 140,
			render: (text: number) => <>{text === 1 ? '全盘' : '抽盘'}</>,
		},
		{
			title: '盘点结论',
			dataIndex: 'stocktakeConclusion',
			align: 'center',
			width: 200,
			render: (text: string) => <span>{text || '--'}</span>,
		},
	]

	return (
		<div className={styles.admittanceAdd}>
			<div className={`${styles.content} ${styles.formDetils}`}>
				<CustomTable
					columns={columns}
					pagination
					total={total}
					params={params}
					callback={(pagination: any) => {
						setParams(pagination)
					}}
					loading={loading}
					dataSource={tableList}
				/>
			</div>
		</div>
	)
})
export default connect(({user}: any) => ({user}))(standbyAdd)
